#include <bits/stdc++.h>
using namespace std;
int n, head;
int a[100001], b[100001];
int q;
int main()
{
    cin >> q;
    while (q--)
    {
        stack<int> st;
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 1; i <= n; i++)
            cin >> b[i];
        head = 1;
        for (int i = 1; i <= n; i++)
        {
            st.push(a[i]);
            while (st.top() == b[head])
            {
                st.pop();
                head++;
                if (st.empty())
                    break;
            }
        }
        if (st.empty())
            puts("Yes");
        else
            puts("No");
    }
}